#!/bin/sh
TFILE="/media/testdrive/result.txt"

# Esperamos hasta que se haya completado el arranque
while ! test -f /var/run/runlevel; do
	sleep 1
done

echo "----- STARTING TEST -----"
echo " EXECUTING TEST IN `pwd`" > $TFILE

# Empezamos el test instalando requisitos
OD="/usr/local/opendomo"
su -c "$OD/updatePackageList.sh" admin >> $TFILE
if su -c "$OD/installPackage.sh motion odvideo" admin >> $TFILE 
then
	if su -c "$OD/updateInstalledPackages.sh" admin >> $TFILE
	then
		echo "OK" >> $TFILE
	else
		echo "FAILED" >> $TFILE
		reboot
	fi
else
	echo "FAILED" >> $TFILE
	reboot
fi

# Superada la primera fase, verificamos el funcionamiento de los módulos
mkdir -p /media/testdrive/video
#OC="$OD/services/config"
su -c "$OD/addStorage.sh /media/testdrive/video " admin >> $TFILE
su -c "$OD/addIPCam.sh Test http://localhost/images/demo_camroom01.jpg" admin >> $TFILE
su -c "/etc/init.d/motion_surveillance start" admin >> $TFILE
sleep 2
if wget -s http://localhost:8081/ >> $TFILE
then
	echo "OK" >> $TFILE
else
	echo "FAILED" >> $TFILE
fi
reboot
